import java.util.Arrays;

/**
 * @author LKQ
 * @date 2021/12/28 21:57
 * @description
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int thirdMax(int[] nums) {
        Arrays.sort(nums);
        for (int i = nums.length - 1, diff = 1; i >= 1; i--) {
            if (nums[i] != nums[i - 1] && ++diff == 3) {
                // 此时 nums[i] 就是第三大的数
                return nums[i];
            }
        }
        return nums[nums.length - 1];
    }
}
